class Solution:
    # 返回从上到下每个节点值列表，例：[1,2,3]
    def PrintFromTopToBottom(self, root):
        # write code here 需要返回空列表
        if not root:
            return []
        # 将节点放到列表中就可以开始遍历节点了
        curStack = [root]
        res = []
        while curStack:
            nextStack = []
            # list没有left和right属性但是list里面的元素有
            for i in curStack:
                if i.left: nextStack.append(i.left)
                if i.right: nextStack.append(i.right)
                res.append(i.val)
            curStack = nextStack
        return res